package com.pg.agent.engine.app.controller;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.pg.base.util.PgHttpUtil;

/**
 * @author hhp
 */
public class TestApp {

    public static void main(String[] args) {

        String token = getToken();

        JSONObject jsonObject = new JSONObject();

        JSONArray messageList = new JSONArray();

        messageList.add(JSON.parse("{\"role\": \"user\",\"content\": \"你好\"}"));
        jsonObject.put("messages",messageList);
        String mgs = PgHttpUtil.postBody("https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ernie-3.5-8k-0205?access_token="+token,null,JSON.toJSONString(jsonObject));

        System.out.println(mgs);
    }

    public static String getToken(){

        String result = PgHttpUtil.get("https://aip.baidubce.com/oauth/2.0/token?grant_type=client_credentials&client_id=iWmbSPBFy4oXH5NeG8QNeLaB&client_secret=aNrI6vkhPTr4tGhbTBgPECwdpTdqGzl2",null,null);
        System.out.println(result);
        JSONObject resultJSON = JSON.parseObject(result);

        return resultJSON.getString("access_token");
    }
}
